package com.lin.cloud.disk.controller;


import com.github.pagehelper.PageInfo;
import com.lin.cloud.disk.common.utils.Result;
import com.lin.cloud.disk.document.CompanyStatusDocument;
import com.lin.cloud.disk.entity.dto.DepartmentDTO;
import com.lin.cloud.disk.entity.pojo.Company;
import com.lin.cloud.disk.entity.request.*;
import com.lin.cloud.disk.entity.request.company.*;
import com.lin.cloud.disk.manage.ICompanyManageService;
import com.lin.cloud.disk.service.ICompanyService;
import com.lin.cloud.disk.service.ICompanyStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * (Company)表控制层
 *
 * @author ljc
 * @since 2020-12-10 16:44:59
 */
@RestController
@RequestMapping("/api/company")
@Slf4j
@Api(tags = "公司控制器")
public class CompanyController {


    @Resource
    private ICompanyManageService companyManageService;

    @Resource
    private ICompanyService companyService;

    @Resource
    private ICompanyStatusService companyStatusService;


    @PostMapping(value = "/departmentTree")
    @ApiOperation(value = "获取公司部门权限列表")
    public Result<List<DepartmentDTO>> getCompanyDepartmentList(@RequestBody @Validated GetCompanyDepartmentTreeRequest request){
        return Result.success(companyManageService.getCompanyDepartmentList(request));
    }

    @PutMapping(value = "/modifyCompanyInfo")
    @ApiOperation(value = "修改公司主体信息")
    public Result modifyCompanyInfo(@RequestBody @Validated ModifyCompanyInfoRequest request){
        companyService.modifyCompanyInfo(request);
        return Result.success();
    }

    @PostMapping(value = "/addCompanyInfo")
    @ApiOperation(value = "添加公司主体信息")
    public Result addCompanyInfo(@RequestBody @Validated AddCompanyInfoRequest request){
        companyManageService.addCompanyInfo(request);
        return Result.success();
    }

    @DeleteMapping(value = "/deleteCompany")
    @ApiOperation(value = "删除公司主体信息")
    public Result deleteCompany(@RequestBody @Validated DeleteCompanyRequest request){
        companyService.deleteCompany(request);
        return Result.success();
    }

    @PostMapping(value = "/getCompanyPageList")
    @ApiOperation(value = "获取公司主体信息分页列表")
    public Result<PageInfo<Company>> getCompanyPageList(@RequestBody @Validated GetCompanyPageListRequest request){
        PageInfo<Company> companyPageList = companyService.getCompanyPageList(request);
        return Result.success(companyPageList);
    }

    @PutMapping(value = "/retrieveCompany")
    @ApiOperation(value = "找回公司主体信息")
    public Result retrieveCompany(@RequestBody @Validated RetrieveCompanyRequest request){
        companyService.retrieveCompany(request);
        return Result.success();
    }

    @PutMapping(value = "/reviewCompanyStatus")
    @ApiOperation(value = "审核公司信息")
    public Result reviewCompanyStatus(@RequestBody @Validated ReviewCompanyStatusRequest request){
        companyService.reviewCompanyStatus(request);
        return Result.success();
    }

    @GetMapping(value = "/findCompanyStatusTrace/{companyId}")
    @ApiOperation(value = "查看公司状态链路")
        public Result<List<CompanyStatusDocument>> findCompanyStatusTrace(@PathVariable("companyId") Long companyId){
        List<CompanyStatusDocument> traceList = companyStatusService.findCompanyStatusTrace(companyId);
        return Result.success(traceList);
    }

    /**
     * 获取可用的公司
     * @return
     */
    @GetMapping("/availableCompany")
    @ApiOperation(value = "获取可用的公司")
    public Result<List<Company>> getAvailableCompany(){
        List<Company> companyList = companyService.getAvailableCompany();
        return Result.success(companyList);
    }

}